home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************
- SPELLTXT.CPP
-
- @DOC SPELLTXT
- @MODULE SPELLTXT - CEditView Spelling checker |
-
- SPELL CHECKER RULES: <nl>
- - text is considered to be a word if it is not longer than 63 letters
-
- PROCEDURE: <nl>
- Spelling starts with <mf TSpelText::StartSpell>
- If the word which is not in dictionary occures there, than dialog
- is being started and suggestion is being offered.
- Spelling continues in terms of <mf TSpellText::FindNextNotExistWord>
- function which returns TRUE if it finds word that doesn't exist
- in dictionary. That word is also in m_szString buffer,
- and m_WordBegPos marks its beginning and m_WordEndPos marks its end.
- After that suggestion for that nonexisting word is being asked.
- We continue from m_lEndWord + 1 word in FindNextNotExistWord()
- function.
-
- PUBLIC MEMBER FUNCTIONS:
- <mf TSpellText::TSpellText> <nl>
- <mf TSpellText::StartSpell> <nl>
- <mf TSpellText::SelectNotExistSpellWord> <nl>
- <mf TSpellText::FindNextNotExistWord> <nl>
- <mf TSpellText::FindNotExistInBoundary> <nl>
- <mf TSpellText::ReplaceWord> <nl>
-
- You should also see TSpellText base class: TSpellCheck (defined
- in SPELL.CPP)
-
- Spelling of text (only modul which depends of program)
- ********************************************************************/
-
- #include "stdafx.h"
- #pragma hdrstop
-
- #include <stdio.h>
- #include "resource.h"
- #include "spelltxt.h"
-
-
- /********************************************************************
- TSpellText
-
- Class for spelling - inhereted from TSpellChecker
- ********************************************************************/
-
-
-
- /*-------------------------------------------------------------------
- TSpellText::TSpellText
- -------------------------------------------------------------------*/
-
- TSpellText::TSpellText(CEditView *pEditView, TSpellingChecker *pSpellChecker)
- {
- m_pEditView = pEditView;
- m_pSpellChecker = pSpellChecker;
- }
-
- /*-------------------------------------------------------------------
- TSpellText - destructor
- -------------------------------------------------------------------*/
-
- TSpellText::~TSpellText()
- {
- }
-
- /*-------------------------------------------------------------------
- StartSpell
- @mfunc
-
- Start of spelling, showing of dialog...
-
- WORK EXPLANATION: <nl>
- Starting position from which spelling starts is being determined
- and than first word is being searched from that position.
-
- If there is no word from to position we go Out.
- If there is word from to position, than loop is being started.
- LOOP
- It is being checked whether word exists in dictionary.
- If there IS word than we go to next word or we go out of loop
- (if we have reached the end or if there are no more words).
- If there IS NO word than we go out of loop.
- DIALOG IS BEING STARTED
- This pointer is being forwarded into dialog, and searching process
- is being continued there in the same way as till now.
-
- @rdesc
- Returns TRUE if the message "Spelling check is complete" should be
- displayed (checking string was complete and dialog box was never
- displayed - actually this means that string are correct).
- -------------------------------------------------------------------*/
-
- BOOL TSpellText::StartSpell(int nStartPos, int nEndPos)
- {
- HCURSOR hOldCursor;
- BOOL fFoundErrorWords;
- BOOL fReturn;
-
- if(nStartPos > nEndPos)
- {
- m_SpellBegPos = nEndPos;
- m_SpellEndPos = nStartPos;
- }
- else {
- m_SpellBegPos = nStartPos;
- m_SpellEndPos = nEndPos;
- }
-
- if(m_SpellBegPos >= m_SpellEndPos)
- {
- // if there is nothing to spell
- return TRUE;
- }
-
- // Set the cursor to the hourglass and save the previous cursor.
- hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
-
- m_WordBegPos = m_SpellBegPos;
- m_WordEndPos = m_SpellEndPos;
-
- fFoundErrorWords = FindNotExistInBoundary();
-
- //Restore the previous cursor.
- SetCursor(hOldCursor);
-
- // here goes the message which notifies that spelling is over
-
- if(fFoundErrorWords == TRUE)
- {
- // this means we have found the word which doesn't exist neither in
- // spell nor in change all buffer (which is empty anyway because class
- // has just been created)
- TSpellDlg SpellDlg(m_pEditView, this);
-
- if(SpellDlg.DoModal() == IDOK)
- fReturn = TRUE;
- else
- fReturn = FALSE;
- }
- else
- {
- fReturn = TRUE;
- }
-
- return fReturn;
- }
-
- /*-------------------------------------------------------------------
- SelectNotExistSpellWord
- @mfunc
-
- Selects word which is from m_lBeginWord to m_lEndWord in DocText object,
- and moves screen so that word can be seen on it.
- -------------------------------------------------------------------*/
-
- void TSpellText::SelectNotExistSpellWord()
- {
- m_pEditView->GetEditCtrl().SetSel(m_WordBegPos, m_WordEndPos);
- }
-
- /*-------------------------------------------------------------------
- FindNextNotExistWord
- @mfunc
-
- Starting from m_WordEndPos position we search for the next word
- which is not in dictionary or in changeAll buffer.
-
- @rdesc
- TRUE if we have found the word which doesn't exist in dictionary. <nl>
- FALSE if we haven't found the word which doesn't exist in dictionary. <nl>
-
- -------------------------------------------------------------------*/
-
- BOOL TSpellText::FindNextNotExistWord()
- {
- m_WordBegPos = m_WordEndPos;
- m_WordEndPos = m_SpellEndPos;
-
- if(m_WordBegPos >= m_WordEndPos)
- {
- return FALSE;
- }
- return FindNotExistInBoundary();
- }
-
- /*-------------------------------------------------------------------
- FindNotExistInBoundary
- @mfunc
-
- Finds nonexisting word within already prepared borders:
- m_WordBegPos and m_WordEndPos
-
- If the word which has been found here isn't in dictionary but
- in changeAll buffer than lets replace it here with that word from
- changeAll buffer.
-
- @rdesc
- TRUE if we have found the word which doesn't exist in dictionary. <nl>
- FALSE if we haven't found the word which doesn't exist in dictionary. <nl>
- -------------------------------------------------------------------*/
-
- BOOL TSpellText::FindNotExistInBoundary()
- {
- while(TRUE)
- {
- const char *pszWord; // pointer to the beginning of the word
-
- if(GetFirstWordPos(m_WordBegPos, TRUE, TRUE, FALSE,
- &m_WordBegPos, &m_WordEndPos) == FALSE)
- {
- return FALSE;
- }
-
- // if word has been found outside of selection
- if(m_WordBegPos > m_SpellEndPos)
- {
- return FALSE;
- }
-
- // WordPos contains beginning of the word
-
- // Get text after m_WordBegPos
- // Because we use CEdit control we can get only complete text or
- // line, so we will get line and point pszWord to the text of the word
- char *pszLine;
- int nLineIdx;
- CEdit & EditCtrl = m_pEditView->GetEditCtrl();
-
- nLineIdx = EditCtrl.LineFromChar(m_WordBegPos);
- pszLine = (char *)malloc(EditCtrl.LineLength(nLineIdx) + 1 + 8);
- memset(pszLine, 0, EditCtrl.LineLength(nLineIdx) + 1 + 8);
- EditCtrl.GetLine(nLineIdx, pszLine, EditCtrl.LineLength(nLineIdx) + 1);
-
- pszWord = pszLine + (m_WordBegPos - EditCtrl.LineIndex(nLineIdx));
-
- // Whether word starts with '_'
- if(*pszWord == '_')
- {
- m_WordBegPos = m_WordEndPos;
- m_WordEndPos = m_SpellEndPos;
- if(m_WordBegPos >= m_SpellEndPos)
- {
- free(pszLine);
- return FALSE;
- }
- continue;
- }
-
- // we are ignoring words this long
- if(m_WordEndPos - m_WordBegPos > 63)
- {
- // we are ignoring words this long
- m_WordBegPos = m_WordEndPos;
- m_WordEndPos = m_SpellEndPos;
- if(m_WordBegPos >= m_SpellEndPos)
- {
- free(pszLine);
- return FALSE;
- }
- continue;
- }
-
- // Taking of words
- m_szString[0] = 0;
- strncat(m_szString, pszWord, m_WordEndPos - m_WordBegPos);
-
- // whether words consists of all numerals
- if(isdigit((unsigned char)*m_szString))
- {
- char *psz = m_szString;
- short fAllNum = TRUE;
-
- while(*psz)
- {
- if(isdigit((unsigned char)*psz) == FALSE) {
- fAllNum = FALSE;
- break;
- }
- psz++;
- }
-
- if(fAllNum) {
- m_WordBegPos = m_WordEndPos;
- m_WordEndPos = m_SpellEndPos;
- if(m_WordBegPos >= m_SpellEndPos)
- {
- free(pszLine);
- return FALSE;
- }
- continue;
- }
- }
-
- // IgnoreWordsInUppercase
- if(m_pSpellChecker->GetIgnoreWordsInUppercase())
- {
- char *psz = m_szString;
- short fAllUpper = TRUE;
-
- while(*psz) {
- if(m_pSpellChecker->IsCharUpper(*psz) == 0)
- {
- fAllUpper = FALSE;
- break;
- }
- psz++;
- }
- if(fAllUpper)
- {
- m_WordBegPos = m_WordEndPos;
- m_WordEndPos = m_SpellEndPos;
- if(m_WordBegPos >= m_SpellEndPos)
- {
- free(pszLine);
- return FALSE;
- }
- continue;
- }
- }
-
- // IgnoreWordWithNumbers
- if(m_pSpellChecker->GetIgnoreWordsWithNumbers())
- {
- char *psz = m_szString;
- short fNumber = FALSE;
-
- while(*psz) {
- if(isdigit((unsigned char)*psz) != 0) {
- fNumber = TRUE;
- break;
- }
- psz++;
- }
- if(fNumber) {
- m_WordBegPos = m_WordEndPos;
- m_WordEndPos = m_SpellEndPos;
- if(m_WordBegPos >= m_SpellEndPos)
- {
- free(pszLine);
- return FALSE;
- }
- continue;
- }
- }
-
- if(m_pSpellChecker->IsWordExist(m_szString) == FALSE)
- {
- // This word doesn't exist in dictionary so we must investigate
- // whether it exists in changAll words buffer
- // If it is than we replace it here and we continue. If it isn't
- // than dialog and suggestion must be shown to user.
-
- CString strReplace;
-
- strReplace = m_pSpellChecker->GetReplacement(m_szString);
- if(strReplace.IsEmpty() == FALSE)
- {
- // Than we have found that replacement for this word exists
- // so lets replace it with pszReplace word.
-
- ReplaceWord((LPCTSTR)strReplace);
- m_WordEndPos = m_WordBegPos + strlen((LPCTSTR)strReplace);
- }
- else
- {
- // we have found the word which doesn't exist in dictionary
- free(pszLine);
- return TRUE;
- }
- }
-
- m_WordBegPos = m_WordEndPos;
- m_WordEndPos = m_SpellEndPos;
- if(m_WordBegPos >= m_SpellEndPos)
- {
- free(pszLine);
- return FALSE;
- }
- }
- }
-
-
- /*-------------------------------------------------------------------
- ReplaceWord
- @mfunc
-
- Replaces current word (for which spell has found that it doesn't
- exist in dictionary) with pszWordForReplace which was sent.
- -------------------------------------------------------------------*/
-
- void TSpellText::ReplaceWord(const char *pszWordForReplace)
- {
- if(pszWordForReplace == NULL)
- {
- return;
- }
-
- CEdit &EditCtrl = m_pEditView->GetEditCtrl();
- EditCtrl.SetSel(m_WordEndPos, m_WordBegPos, TRUE);
- EditCtrl.ReplaceSel(pszWordForReplace);
-
- m_SpellEndPos += strlen(pszWordForReplace) - (m_WordEndPos - m_WordBegPos);
- m_WordEndPos += strlen(pszWordForReplace) - (m_WordEndPos - m_WordBegPos);
- }
-
-
-
- /*-------------------------------------------------------------------
- GetFirstWordPos
- @mfunc
-
- Finds first word located behind pos position
-
- @parm pos - position
- @parm fInclBackPos -if it is possible to return the word located in
- front of pos. E.g. if pos is within a word
- is it possible to return position on that word
- (lower than pos).
- @parm fInclSingleQuote -if single quote (') can be found within word
- (not at the end or at the beginning of word
- but only within)
- @parm fIgnoreTexKeywords -ignoring of UNIX Tex Keyworda i.e. of all words
- starting with '\' (e.g. \doc)
-
- @parm pWordStartPos -pointer to int in which is written position
- of the beginning of the word
- @parm pWordEndPos -pointer to int in which is written position
- of the end of the word(position of the first
- letter behind the word)
-
- @rdesc
- Returns FALSE if the word hasn't been found.
-
- @comm
- Since there can not be tabulators within word, its length
- can be determined as pWordEndPos - pWordStartPos
- -------------------------------------------------------------------*/
-
- int TSpellText::GetFirstWordPos(int pos, BOOL fInclBackPos, BOOL fInclSingleQuote,
- BOOL fIgnoreTexKeywords, int *pWordStartPos, int *pWordEndPos)
- {
- const char *psz;
- const char *pszStart;
-
- CEdit& EditCtrl = m_pEditView->GetEditCtrl();
-
- pszStart = m_pEditView->LockBuffer();
-
- psz = pszStart + pos;
-
-
- if(m_pSpellChecker->IsCharAlpha(*psz))
- {
- // if this is the first letter in string or if there is no letter
- // preceding it
- if(psz == pszStart || (psz != pszStart && m_pSpellChecker->IsCharAlpha(*(psz-1)) == FALSE))
- {
- if(psz == pszStart || *(psz-1) != '\\')
- {
- *pWordStartPos = pos;
- *pWordEndPos = pos + 1;
- psz++;
- if(fInclSingleQuote)
- {
- while(m_pSpellChecker->IsCharAlpha(*psz) || *psz == '\'' || isdigit((unsigned char)*psz))
- {
- psz++;
- (*pWordEndPos)++;
- }
-
- if(psz != pszStart && *(psz-1) == '\'')
- (*pWordEndPos)--;
- }
- else
- {
- while(m_pSpellChecker->IsCharAlpha(*psz) || isdigit((unsigned char)*psz))
- {
- psz++;
- (*pWordEndPos)++;
- }
- }
- m_pEditView->UnlockBuffer();
- return TRUE;
- }
- }
- else
- {
- // if it is allowed we go back to the beginning of word
- // (only for first line)
- if(fInclBackPos)
- {
- while(psz != pszStart)
- {
- if(m_pSpellChecker->IsCharAlpha(*(psz-1)) == FALSE)
- {
- break;
- }
- pos--;
- psz--;
- }
- if(psz == pszStart || *(psz-1) != '\\')
- {
- *pWordStartPos = pos;
- *pWordEndPos = pos + 1;
- psz++;
- if(fInclSingleQuote)
- {
- while(m_pSpellChecker->IsCharAlpha(*psz) || *psz == '\'')
- {
- psz++;
- (*pWordEndPos)++;
- }
- if(psz != pszStart && *(psz-1) == '\'')
- (*pWordEndPos)--;
- }
- else {
- while(m_pSpellChecker->IsCharAlpha(*psz)) {
- psz++;
- (*pWordEndPos)++;
- }
- }
- m_pEditView->UnlockBuffer();
- return TRUE;
- }
- }
- }
-
- while(m_pSpellChecker->IsCharAlpha(*psz))
- {
- psz++;
- }
- }
-
- while(TRUE)
- {
- while(*psz != 0 && m_pSpellChecker->IsCharAlpha(*psz) == FALSE)
- psz++;
- // pos is lost
- if(m_pSpellChecker->IsCharAlpha(*psz) && (psz == pszStart || *(psz-1) != '\\'))
- {
- *pWordStartPos = *pWordEndPos = psz - pszStart;
- (*pWordEndPos)++;
- psz++;
- if(fInclSingleQuote)
- {
- while(m_pSpellChecker->IsCharAlpha(*psz) || *psz == '\'')
- {
- psz++;
- (*pWordEndPos)++;
- }
- if(psz != pszStart && *(psz-1) == '\'')
- (*pWordEndPos)--;
- }
- else
- {
- while(m_pSpellChecker->IsCharAlpha(*psz))
- {
- psz++;
- (*pWordEndPos)++;
- }
- }
- m_pEditView->UnlockBuffer();
- return TRUE;
- }
- break;
- }
- m_pEditView->UnlockBuffer();
- return FALSE;
- }
-
-
-
- /*******************************************************************
- TSpellDlg
-
- Dialog for spelling
- *******************************************************************/
-
- #define IDC_NOT_IN_DIC 101
- #define IDC_COMBO_SUGGEST 102
- #define IDC_BTN_IGNOR 103
- #define IDC_BTN_IGNORALL 104
- #define IDC_BTN_CHANGE 105
- #define IDC_BTN_CHANGEALL 106
- #define IDC_BTN_ADD 107
- #define IDC_BTN_SUGGEST 108
- #define IDC_BTN_OPTIONS 109
-
-
- BEGIN_MESSAGE_MAP(TSpellDlg, CDialog)
- ON_CBN_EDITCHANGE(IDC_COMBO_SUGGEST, CBEditChange_Suggest)
- ON_BN_CLICKED(IDC_BTN_IGNOR, CmIgnore)
- ON_BN_CLICKED(IDC_BTN_IGNORALL, CmIgnoreAll)
- ON_BN_CLICKED(IDC_BTN_CHANGE, CmChange)
- ON_BN_CLICKED(IDC_BTN_CHANGEALL, CmChangeAll)
- ON_BN_CLICKED(IDC_BTN_SUGGEST, CmSuggest)
- ON_BN_CLICKED(IDC_BTN_ADD, CmAdd)
- ON_BN_CLICKED(IDC_BTN_OPTIONS, CmOptions)
- //EV_CHILD_NOTIFY(IDCANCEL, BN_CLICKED, CmCancel),
- END_MESSAGE_MAP()
-
-
- TSpellDlg::TSpellDlg(CWnd * pParent, TSpellText *pSpellDoc)
- : CDialog("Spell", pParent)
- {
- m_pSpellDocument = pSpellDoc;
- }
-
-
- BOOL TSpellDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- //CenterDialog(m_hWnd, FALSE);
-
- SetDlgItemText(IDC_NOT_IN_DIC, m_pSpellDocument->m_szString);
- m_pSpellDocument->SelectNotExistSpellWord();
-
- if(m_pSpellDocument->m_pSpellChecker->GetAlwaysSuggest())
- {
- BOOL fSuggestions = FALSE;
-
- // List of suggestions for word which has not been found is
- // being filled now
- for(int i = 0; i < 10; i++)
- {
- CString strSuggestion = m_pSpellDocument->m_pSpellChecker->GetSuggestion(m_pSpellDocument->m_szString, i);
-
- if(strSuggestion.GetLength() > 0)
- {
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)(LPCTSTR)strSuggestion);
- fSuggestions = TRUE;
- }
- else
- break;
- }
- if(fSuggestions)
- {
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_SETCURSEL, 0, 0);
- }
- else
- {
- char szBuf[40];
-
- LoadString(AfxGetResourceHandle(), IDS_WE_SPELL_NOSUGGESTION, szBuf, sizeof(szBuf));
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)szBuf);
- }
- ::EnableWindow(GetDlgItem(IDC_BTN_SUGGEST)->GetSafeHwnd(), FALSE);
- }
- else
- {
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_RESETCONTENT, 0, 0L);
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)"");
- ::EnableWindow(GetDlgItem(IDC_BTN_SUGGEST)->GetSafeHwnd(), FALSE);
- }
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_LIMITTEXT, 31, 0L);
-
- return TRUE;
- }
-
-
- void TSpellDlg::CBEditChange_Suggest()
- {
- char szBuf[32];
-
- GetDlgItemText(IDC_COMBO_SUGGEST, szBuf, sizeof(szBuf));
- // enabling Suggest only if there is any text
- if(szBuf[0] != 0)
- ::EnableWindow(GetDlgItem(IDC_BTN_SUGGEST)->GetSafeHwnd(), TRUE);
- else
- ::EnableWindow(GetDlgItem(IDC_BTN_SUGGEST)->GetSafeHwnd(), FALSE);
- }
-
-
- void TSpellDlg::CmIgnore()
- {
- GoToNextWord();
- }
-
-
- void TSpellDlg::CmIgnoreAll()
- {
- char szWordNotInDic[64];
-
- GetDlgItemText(IDC_NOT_IN_DIC, szWordNotInDic, sizeof(szWordNotInDic)-1);
- if(szWordNotInDic[0] != 0)
- {
- m_pSpellDocument->m_pSpellChecker->AddToIgnoreAll(szWordNotInDic);
-
- //going to next word
- GoToNextWord();
- }
- }
-
-
- void TSpellDlg::CmChange()
- {
- // Replacing word which doesn't exist in dictionary with suggested word
- // in text box suggest (if there is any) and going on with finding
- // words in text.
-
- char szSuggWord[32];
-
- GetDlgItemText(IDC_COMBO_SUGGEST, szSuggWord, sizeof(szSuggWord)-1);
- if(szSuggWord[0] != 0)
- {
- m_pSpellDocument->ReplaceWord(szSuggWord);
- GoToNextWord();
- }
- }
-
-
- void TSpellDlg::CmChangeAll()
- {
- // Replacing word which doesn't exist in dictionary with suggested word
- // in text box suggest
- // This is done automaticly every time when this word occures.
- // This is done only while we are in this dialog (i.e. in this session)
-
- char szSuggWord[64];
- char szWordNotInDic[64];
-
- GetDlgItemText(IDC_COMBO_SUGGEST, szSuggWord, sizeof(szSuggWord)-1);
- GetDlgItemText(IDC_NOT_IN_DIC, szWordNotInDic, sizeof(szWordNotInDic)-1);
-
- if(szWordNotInDic[0] != 0) {
- m_pSpellDocument->m_pSpellChecker->AddToChangeAll(szWordNotInDic, szSuggWord);
- }
-
- if(szSuggWord[0] != 0) {
- m_pSpellDocument->ReplaceWord(szSuggWord);
- }
- GoToNextWord();
- }
-
-
- void TSpellDlg::CmAdd()
- {
- // Adds word (that we haven't found in dictionary) in custom dictionary
-
- char szWordNotInDic[32];
-
- GetDlgItemText(IDC_NOT_IN_DIC, szWordNotInDic, sizeof(szWordNotInDic)-1);
- if(szWordNotInDic[0] != 0)
- {
- m_pSpellDocument->m_pSpellChecker->AddWord(szWordNotInDic);
-
- //going to next word
- GoToNextWord();
- }
- }
-
-
- void TSpellDlg::CmSuggest()
- {
- char szSuggWord[32];
-
- GetDlgItemText(IDC_COMBO_SUGGEST, szSuggWord, sizeof(szSuggWord)-1);
-
- if(szSuggWord[0] != 0)
- {
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_RESETCONTENT, 0, 0L);
- // List of suggestions for word which has not been found is
- // being filled now
-
- BOOL fSuggestions = FALSE;
-
- // List of suggestions for word which has not been found is
- // being filled now
- for(int i = 0; i < 10; i++)
- {
- CString strSuggestion = m_pSpellDocument->m_pSpellChecker->GetSuggestion(m_pSpellDocument->m_szString, i);
-
- if(strSuggestion.GetLength() > 0)
- {
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)(LPCTSTR)strSuggestion);
- fSuggestions = TRUE;
- }
- else
- break;
- }
- if(fSuggestions)
- {
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_SETCURSEL, 0, 0);
- }
- else
- {
- char szBuf[40];
-
- LoadString(AfxGetResourceHandle(), IDS_WE_SPELL_NOSUGGESTION, szBuf, sizeof(szBuf));
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)szBuf);
- }
-
- ::EnableWindow(GetDlgItem(IDC_BTN_SUGGEST)->GetSafeHwnd(), FALSE);
- }
- }
-
-
- void TSpellDlg::CmOptions()
- {
- TSpellOptionsDynamicDlg(this, m_pSpellDocument).DoModal();
- }
-
- void TSpellDlg::GoToNextWord()
- {
- HCURSOR hcurSave = ::SetCursor(LoadCursor(NULL, IDC_WAIT));
-
- // we reject offered suggestion for a found word and we search for a next
- // word which is not in dictionary
-
- if(m_pSpellDocument->FindNextNotExistWord() == TRUE)
- {
- // Restore the previous cursor.
- ::SetCursor(hcurSave);
-
- // word which hasn't been found in dictionary is being set
- // in tekstBox IDC_NOT_IN_DIC
- SetDlgItemText(IDC_NOT_IN_DIC, m_pSpellDocument->m_szString);
- // We have found word which doesn't exist in dictionary.
- // Lets select it now.
- m_pSpellDocument->SelectNotExistSpellWord();
-
- if(m_pSpellDocument->m_pSpellChecker->GetAlwaysSuggest())
- {
- BOOL fSuggestions = FALSE;
-
- // List of suggestions for word which has not been found is
- // being filled now
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_RESETCONTENT, 0, 0L);
- for(int i = 0; i < 10; i++)
- {
- CString strSuggestion = m_pSpellDocument->m_pSpellChecker->GetSuggestion(m_pSpellDocument->m_szString, i);
-
- if(strSuggestion.GetLength() > 0)
- {
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)(LPCTSTR)strSuggestion);
- fSuggestions = TRUE;
- }
- else
- break;
- }
- if(fSuggestions)
- {
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_SETCURSEL, 0, 0);
- }
- else
- {
- char szBuf[40];
-
- LoadString(AfxGetResourceHandle(), IDS_WE_SPELL_NOSUGGESTION, szBuf, sizeof(szBuf));
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)szBuf);
- }
- ::EnableWindow(GetDlgItem(IDC_BTN_SUGGEST)->GetSafeHwnd(), FALSE);
- }
- else
- {
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_RESETCONTENT, 0, 0L);
- SendDlgItemMessage(IDC_COMBO_SUGGEST, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)"");
- ::EnableWindow(GetDlgItem(IDC_BTN_SUGGEST)->GetSafeHwnd(), FALSE);
- }
- }
- else
- {
- // There are no more words in document which do not
- // exist in dictionary
-
- // Restore the previous cursor.
- ::SetCursor(hcurSave);
- EndDialog(IDOK);
- }
- }
-
- #undef IDC_NOT_IN_DIC
- #undef IDC_COMB_SUGGEST
- #undef IDC_BTN_IGNOR
- #undef IDC_BTN_IGNORALL
- #undef IDC_BTN_CHANGE
- #undef IDC_BTN_CHANGEALL
- #undef IDC_BTN_SUGGEST
- #undef IDC_BTN_ADD
- #undef IDC_BTN_OPTIONS
-
-
-
- /*******************************************************************
- TSpellOptionsDynamicDlg
-
- Dialog for dinamic change of options while spelling
- *******************************************************************/
-
- #define IDC_CHECK_ALWAYSSUGGEST 101
- #define IDC_CHECK_IGNOREUPPERCASE 102
- #define IDC_CHECK_IGNORENUMBERS 103
-
-
- BEGIN_MESSAGE_MAP(TSpellOptionsDynamicDlg, CDialog)
- ON_BN_CLICKED(IDOK, OnOK)
- END_MESSAGE_MAP()
-
-
- TSpellOptionsDynamicDlg::TSpellOptionsDynamicDlg(CWnd * pParent, TSpellText *pSpellDoc)
- : CDialog("SpellOptions_Dynamic", pParent)
- {
- m_pSpellDocument = pSpellDoc;
- }
-
-
- BOOL TSpellOptionsDynamicDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- //CenterDialog(HWindow, TRUE);
-
- CheckDlgButton(IDC_CHECK_ALWAYSSUGGEST, m_pSpellDocument->m_pSpellChecker->GetAlwaysSuggest());
- CheckDlgButton(IDC_CHECK_IGNOREUPPERCASE, m_pSpellDocument->m_pSpellChecker->GetIgnoreWordsInUppercase());
- CheckDlgButton(IDC_CHECK_IGNORENUMBERS, m_pSpellDocument->m_pSpellChecker->GetIgnoreWordsWithNumbers());
-
- return TRUE;
- }
-
- void TSpellOptionsDynamicDlg::OnOK()
- {
- m_pSpellDocument->m_pSpellChecker->SetAlwaysSuggest(IsDlgButtonChecked(IDC_CHECK_ALWAYSSUGGEST));
- m_pSpellDocument->m_pSpellChecker->SetIgnoreWordsInUppercase(IsDlgButtonChecked(IDC_CHECK_IGNOREUPPERCASE));
- m_pSpellDocument->m_pSpellChecker->SetIgnoreWordsWithNumbers(IsDlgButtonChecked(IDC_CHECK_IGNORENUMBERS));
- EndDialog(IDOK);
- }
-
- #undef IDC_CHECK_ALWAYSSUGGEST
- #undef IDC_CHECK_IGNOREUPPERCASE
- #undef IDC_CHECK_IGNORENUMBERS
-
-